<template>
  <div class="text" v-text="btnText"  @click="clickGetSMS">
  </div>
</template>

<script type="text/ecmascript-6">
  import Public from '@/assets/js/public';
  let countDownNum = null;
  let countDownId = null;
  export default {
    /** kebab-case */
    name: 'btn-sms-code',

    data() {
      return {
        btnDisabled: false,
        btnText: '发送验证码'
      };
    },
    /** 在声明 prop 的时候，其命名应该始终使用 camelCase，而在模板和 JSX 中应该始终使用 kebab-case。
     String/Number/Boolean/Function/Object/Array/Symbol */
    props: {},

    components: {},

    methods: {
      getIcon(icon) {
        return Public.ossImg + icon + '.svg';
      },
      clickGetSMS() {
        if (this.btnDisabled) {
          return;
        }
        this.$emit('clickSMSBtn');
        // this.setTimeCountDown();
      },
      setTimeCountDown(second = 2 * 60) {
        countDownNum = second;
        this.startCountDown();
        countDownId = setInterval(() => {
          countDownNum--;
          this.btnText = '等待' + countDownNum + '秒';
          // console.log(countDownNum);
          if (countDownNum <= 0) {
            this.finishCountDown();
          }
        }, 1000);
      },
      startCountDown() {
        this.btnDisabled = true;
      },
      finishCountDown() {
        this.btnDisabled = false;
        this.btnText = '发送验证码';
        clearInterval(countDownId);
      }
    },
    computed: {},
    watch: {
      // 监听具体数据变化，并做相应的处理
    }
  };
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  @import "../../assets/stylus/main.styl";
  .flex-r
    flex-x()

  .flex-c
    flex-y()

  .center
    flex-center()

  .divider
    divider()

  .space
    space()
  .text
    word-vw(14px,main-color)
</style>
